/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-08-08 17:40:10
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-08-08 17:40:22
 * @FilePath: \passiflora-edulis-sims\src\utils\FontUtil.ts
 * @Description: 字体的 相关方法合集
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import type { IFontConfig } from 'src/interfaces/IFont'
export async function loadFont(
  fontName: string,
  fontPath: string,
  config: Partial<IFontConfig> = {}
) {
  const fontFamily = config.family || fontName
  const fontFace = new FontFace(fontFamily, `url(${fontPath})`, {
    style: config.style || 'normal',
    weight: String(config.weight) || '400',
    display: config.display || 'swap',
  })

  try {
    // 加载字体
    const loadedFont = await fontFace.load()
    // 添加到文档
    document.fonts.add(loadedFont)
    console.log(`Font ${fontFamily} loaded successfully`)
    return true
  } catch (error) {
    console.error(`Failed to load font ${fontFamily}:`, error)
    return false
  }
}
